#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int N = 0;
    cin >> N;
    vector<int> que, pos(N, -1);
    string op;
    int num = 0;
    while (cin >> op)
    {
        if (op == "query") {
            int minn = que.size();
            for (int i = 1; i < N; i++) {
                minn = min(minn, pos[i]);
            }
            cout << minn + 1 << endl;
        }
        else {
            cin >> num;
            if (op == "add") que.emplace_back(num);
            else if (op == "sync") { if (num > 0 && num < N && pos[num] + 1 < que.size()) ++pos[num]; }
        }
    }
    return 0;
}